home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- //
- // Creation Date: 2001
- // Author: dbrins
- //
-
-
- global string $gAEAttrPresetCurrentTarget;
- global float $gAEAttrPresetBlend;
- global string $gAEAttrPresetCopyObj = "";
- global string $gAEAttrPresetSelList[];
- global int $gAEAttrPresetValidNotes;
- global string $gAEAttrPresetExcludeAttrs[] = {
- // for now simply reject doubleSided: bug159621
- // Eventually this could check for membership in attribute
- // groupings for selective loading of attributes
- "doubleSided",
- "rotateQuaternionX",
- "rotateQuaternionY",
- "rotateQuaternionZ",
- "rotateQuaternionW",
- "outStippleThreshold",
- "face",
- "boundary",
- "currentDisplayLayer",
- "useComponentPivot",
- "currentRenderLayer", // layer needs to exist
- "springStiffness",
- "springDamping",
- "springRestLength",
- "caching",
- "nodeState"
- };
- global string $gAEAttrPresetExcludeNodeAttrs[] = {
- "timeToUnitConversion.output", // should be output-only
- "unitToTimeConversion.output",
- "oceanShader.outFoam",
- "solidNoise.outColorR",
- "solidNoise.outColorG",
- "solidNoise.outColorB",
- "solidNoise.outAlpha",
- "joint.rotatePivotX", // normalised, so they affect one another
- "joint.rotatePivotY",
- "joint.rotatePivotZ",
- "samplerInfo.normalCameraX", // normalised, so they affect one another
- "samplerInfo.normalCameraY",
- "samplerInfo.normalCameraZ",
- "samplerInfo.rayDirectionX", // normalised, so they affect one another
- "samplerInfo.rayDirectionY",
- "samplerInfo.rayDirectionZ",
- "airField.maxDistance", // can be set below their minimum value by presets
- "dragField.maxDistance",
- "gravityField.maxDistance",
- "newtonField.maxDistance",
- "radialField.maxDistance",
- "turbulenceField.maxDistance",
- "uniformField.maxDistance",
- "volumeAxisField.maxDistance",
- "vortexField.maxDistance",
- "torusField.maxDistance",
- "FurFeedback.realUSamples", // dynamic/internal, affected by other attributes
- "FurFeedback.realVSamples",
- "globalStitch.updateSampling", // reset by the 'sampling' attribute
- "fluidShape.controlPoints.xValue",
- "fluidShape.controlPoints.yValue",
- "fluidShape.controlPoints.zValue",
- "fluidShape.weights",
- "fluidShape.seed"
- };
-
- // Decide which parameters we will use from the current preset.
- // If the attribute is in the excluded attrs list above, or
- // the type.attr string is in the excluded node.attrs list above,
- // this attribute will neither be SAVED to a preset file *or*
- // READ back in from a preset file.
- //
- global proc int validNodeTypeAttrForCurrentPreset( string $type,
- string $attr )
- {
- global string $gAEAttrPresetExcludeAttrs[];
- global string $gAEAttrPresetExcludeNodeAttrs[];
-
- string $oldAttr = "";
- int $i;
-
- // For the purposes of matching the above string
- // arrays, we should strip off any multi indexing
- // from the attr names. Paranoia of a pathological
- // test case causing an infinite loop means we're
- // capping the multi parent hierarchy at 10 levels...
- //
- for( $i = 0; $oldAttr != $attr && $i < 10; $i++ ) {
- // This is our loop control.
- //
- $oldAttr = $attr;
-
- // For the following example: parent[1].child[2].x
- // we'd loop through three times with these results
- // after each execution of the following substitution.
- //
- // 1) $oldAttr = parent[1].child[2].x
- // $attr = parent.child[2].x
- // 2) $oldAttr = parent.child[2].x
- // $attr = parent.child.x
- // 3) $oldAttr = parent.child.x
- // $attr = parent.child.x
- //
- $attr = substitute( "\\[[0-9]*\\]", $attr, "" );
- }
-
- // Check attributes regardless of node type.
- //
- if (stringArrayCount($attr, $gAEAttrPresetExcludeAttrs) > 0) {
- return 0;
- }
-
- // Check attributes with specific node types.
- //
- string $excludeNodeAttr = $type + "." + $attr;
- if (stringArrayCount($excludeNodeAttr, $gAEAttrPresetExcludeNodeAttrs) > 0) {
- return 0;
- }
-
- return 1;
- }
-
- global proc int validAttrForCurrentPreset( string $attr ) {
- global string $gAEAttrPresetCurrentTarget;
- string $type = `nodeType $gAEAttrPresetCurrentTarget`;
-
- return validNodeTypeAttrForCurrentPreset( $type, $attr );
- }
-
- //
- // handle string preset values
- //
- global proc blendAttrStr( string $attr, string $str )
- {
- global string $gAEAttrPresetCurrentTarget;
- global float $gAEAttrPresetBlend;
- global int $gAEAttrPresetValidNotes;
- if( $gAEAttrPresetBlend > 0.5 ){
- if( size($gAEAttrPresetCurrentTarget) > 0){
- if( validAttrForCurrentPreset( $attr ) ){
- string $objAttr = $gAEAttrPresetCurrentTarget + "." + $attr;
- if($attr == "notes" || $attr == "nts") {
- $gAEAttrPresetValidNotes = 1;
- // we know what kind of dynamic attr notes has to be
- // so we can create it. A blatant special case if we ever saw one
- // in future we should write out a blendDynAttr command which
- // specifies the type info for dynamic attributes to be created
- if(!objExists( $objAttr )) {
- if( catch(`addAttr -dt "string" -ln "notes" -sn "nts" $gAEAttrPresetCurrentTarget`)) {
- error(" Could not create dynamic attribute: " + $objAttr);
- }
- }
- }
- if(objExists( $objAttr ) && `getAttr -settable $objAttr`) {
- setAttr -type "string" $objAttr $str;
- }
- }
- }
- }
- }
-
- //
- // handle scalar preset values
- //
- global proc blendAttr( string $attr, float $val )
- {
- global string $gAEAttrPresetCurrentTarget;
- global float $gAEAttrPresetBlend;
- global string $gAEAttrPresetCopyObj;
-
- // print ("setting Attr " + $attr + "\n" );
- if( size($gAEAttrPresetCurrentTarget) > 0){
- if( validAttrForCurrentPreset( $attr ) ){
- string $objAttr = $gAEAttrPresetCurrentTarget + "." + $attr;
- if( `getAttr -se $objAttr`) {
- if( $gAEAttrPresetBlend < 0.999 ){
- $targAttr = $gAEAttrPresetCopyObj + "." + $attr;
- if( objExists( $targAttr ) ){
- string $attrType = `getAttr -type $targAttr`;
- switch ($attrType) {
- case "enum":
- if( $gAEAttrPresetBlend < 0.5 ){
- $val = getAttr( $targAttr );
- }
- setAttr ($gAEAttrPresetCurrentTarget + "." + $attr) $val;
- break;
- case "bool":
- case "short":
- case "long":
- case "byte":
- case "char":
- int $intVal = (int)($val * $gAEAttrPresetBlend
- + getAttr($targAttr) * (1-$gAEAttrPresetBlend));
- setAttr ($gAEAttrPresetCurrentTarget + "." + $attr) $intVal;
- break;
-
- // These cases are expected in default
- //
- // case "float":
- // case "floatLinear":
- // case "double":
- // case "doubleLinear":
- // case "doubleAngle":
- // case "time":
- //
- default:
- $val = $val * $gAEAttrPresetBlend
- + getAttr($targAttr) * (1-$gAEAttrPresetBlend);
- setAttr -c ($gAEAttrPresetCurrentTarget + "." + $attr) $val;
- break;
- }
- }
- } else {
- setAttr -c $objAttr $val;
- }
- }
- }
- }
- }
-
- //
- // Clean up after setting preset values
- //
- global proc endAttrPreset()
- {
- // print ("endAttrPreset\n" );
- global float $gAEAttrPresetBlend;
- global string $gAEAttrPresetCopyObj;
- global string $gAEAttrPresetSelList[];
-
- global string $gAEAttrPresetCurrentTarget;
- global int $gAEAttrPresetValidNotes;
-
- // if we didn't find any notes in the preset, and the node has
- // ols out of date notes, remove them
- if($gAEAttrPresetValidNotes == 0) {
- string $notesAttr = $gAEAttrPresetCurrentTarget + ".notes";
- if(objExists( $notesAttr )) {
- if( catch(`deleteAttr -at "notes" $gAEAttrPresetCurrentTarget`)) {
- error(" Could not delete dynamic attribute: " + $notesAttr);
- }
- }
- }
- $gAEAttrPresetCopyObj = "";
- $gAEAttrPresetSelList = {};
- }
-
- //
- // Initialize for preset calls
- //
- global proc startAttrPreset( string $nodeType )
- {
- global string $gAEAttrPresetCurrentTarget;
- global float $gAEAttrPresetBlend;
- global string $gAEAttrPresetSelList[];
- global string $gAEAttrPresetCopyObj;
- global int $gAEAttrPresetValidNotes;
-
- $gAEAttrPresetValidNotes = 1;
- if( objExists( $gAEAttrPresetCurrentTarget ) ){
- string $type = nodeType($gAEAttrPresetCurrentTarget);
- if( $type != $nodeType ){
- warning( "Preset type" + $nodeType + " does not match current selection." );
- $gAEAttrPresetCurrentTarget = "";
- } else {
- $gAEAttrPresetCopyObj = $gAEAttrPresetCurrentTarget;
-
- if( $gAEAttrPresetBlend > 0.5 ){
- // mark current notes as invalid
- // we can delete the attr later if we don't get new notes from the preset
- $gAEAttrPresetValidNotes = 0;
- }
-
- if( $gAEAttrPresetBlend > 0.7 ){
- // Delete relevant multi entries
- string $multies[] = `attributeInfo -m 1 -and -w 1 -and -h 0 $gAEAttrPresetCurrentTarget`;
- string $mult;
- for ($mult in $multies ){
- string $nodeName = $gAEAttrPresetCurrentTarget +"."+$mult;
- if( objExists( $nodeName ) ){
- int $i, $size;
- string $entries[] = `listAttr -m -st $mult $gAEAttrPresetCurrentTarget`;
- $size = size($entries);
- // do this in reverse order because the widget wants to
- // reconnect to the lowest index when its attr is deleted out
- // from under it, so we don't want it to keep reconnecting all the time
- for( $i = $size -1; $i >= 0; $i-- ){
- string $multiName = $gAEAttrPresetCurrentTarget + "." + $entries[$i];
- string $atrs[] = `listAttr -s $multiName`;
- int $doDelete = 1;
- if( size( $atrs ) > 0 ){
- for ($atr in $atrs)
- {
- string $attrName = $gAEAttrPresetCurrentTarget + "." + $atr;
- if( !objExists( $attrName )
- || `connectionInfo -id $attrName`
- || `connectionInfo -is $attrName`
- || `connectionInfo -il $attrName`){
- // only delete if no children are connected or
- // locked
- $doDelete = 0;
- break;
- }
- }
- } else {
- $doDelete = 0;
- }
- if( $doDelete ){
- removeMultiInstance $multiName;
- }
- }
- }
- }
- }
- }
- } else {
- $gAEAttrPresetCurrentTarget = "";
- }
- }
-